package mmtService;

import java.io.DataOutputStream;
import java.io.IOException;
import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import biz.SendMessage;
import biz.UserBIZ;
import model.JsonPack;
import model.User;
import dao.*;

@SuppressWarnings("serial")
@WebServlet("/AcceptFriends")
public class AcceptFriends extends HttpServlet
{

	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{

				
		String mode = request.getParameter("mode");
		String userPhone = request.getParameter("userPhone");
		String applyPhone = request.getParameter("applyPhone");
		System.out.println(userPhone+"acceptFriendsFrom_"+applyPhone);
		UserBIZ ub = new UserBIZ();
		String messageReturn = "Success";
		if(mode==null||userPhone==null||applyPhone==null)
		{
			System.out.println("AcceptFriendsErrorMode");
			return;
		}
		if(mode.equals("accept"))
		{
			if(ub.dealFriendRequest(userPhone, applyPhone, true))
			{
				messageReturn = "Fail";
			}
			
			
		}
		else if(mode.equals("refuse"))
		{
			
			if(ub.dealFriendRequest(userPhone, applyPhone, false))
			{
				messageReturn = "Fail";
			}
		}
		
		SendMessage.sendMessageReturn(response, messageReturn);
	}

}
